import axios from "axios";
import { ElMessage } from "element-plus";
const request = axios.create({
    baseURL: 'http://127.0.0.1:8000',
    timeout: 10000
})
request.interceptors.request.use(config => {
    const authUrls = ['/login/', '/code/', '/register/',];
    if (authUrls.some(path => config.url.includes(path))) {
        return config;
    }
    if (!config.url.includes('up.qiniup.com')) { // 七牛域名不走拦截
        const token = localStorage.getItem('token')
        console.log('拦截器', token)
        if (token) {
            config.headers.Authorization = `Bearer ${token}`
        } else {
            ElMessage.error('Token丢失')
        }
    }
    return config
})
export default request